{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thread-1: Tue Feb 19 00:20:19 2019\n",
      "Thread-2: Tue Feb 19 00:20:21 2019\n",
      "Thread-1: Tue Feb 19 00:20:21 2019\n",
      "Thread-1: Tue Feb 19 00:20:23 2019\n",
      "Thread-2: Tue Feb 19 00:20:25 2019\n",
      "Thread-1: Tue Feb 19 00:20:25 2019\n",
      "Thread-1: Tue Feb 19 00:20:27 2019\n",
      "Thread-2: Tue Feb 19 00:20:29 2019\n",
      "Thread-2: Tue Feb 19 00:20:33 2019\n",
      "Thread-2: Tue Feb 19 00:20:37 2019\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/python\n",
    "# -*- coding: UTF-8 -*-\n",
    " \n",
    "import thread\n",
    "import time\n",
    " \n",
    "# 为线程定义一个函数\n",
    "def print_time( threadName, delay):\n",
    "   count = 0\n",
    "   while count < 5:\n",
    "      time.sleep(delay)\n",
    "      count += 1\n",
    "      print \"%s: %s\" % ( threadName, time.ctime(time.time()) )\n",
    " \n",
    "# 创建两个线程\n",
    "try:\n",
    "   thread.start_new_thread( print_time, (\"Thread-1\", 2, ) )\n",
    "   thread.start_new_thread( print_time, (\"Thread-2\", 4, ) )\n",
    "except:\n",
    "   print \"Error: unable to start thread\"\n",
    " \n",
    "while 1:\n",
    "   pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
